package com.example.moblie2030606150cjk0420;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class partRVAdapter extends RecyclerView.Adapter<partRVAdapter.ViewHolder> {
    int[] partIds;
    String[] partNames;
    public partRVAdapter(int[] partIds,String[] partNames) {
        this.partIds = partIds;
        this.partNames = partNames;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_main_part, parent, false);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.ivpart.setImageResource(partIds[position]);
        holder.tvpart.setText(partNames[position]);

    }

    @Override
    public int getItemCount() {
        return partIds.length;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView ivpart;
        TextView tvpart;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ivpart = itemView.findViewById(R.id.iv_item_part);
            tvpart = itemView.findViewById(R.id.tv_item_part);

        }
    }
}
